<script type="text/javascript" src="<?php echo base_url()?>js/back_end/jquery-latest.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>js/back_end/jquery.tablesorter.js"></script>
<script type="text/javascript">
	$(function() {		
		$("#myTable").tablesorter({sortList:[[0,0],[3,1]]});
	});
	function edit_order(id, seft){		 
		var order = $(seft).val();
		if(order == 0){
			return;
		}		
		window.location = $.trim($("#domain").val()) + "back_end/admin_categories/edit_order/" + id +"/" + order;
	}
</script>
<style>
	a{color: #090; text-decoration: none;}
	a:hover {
		color: #FF4400;
		text-decoration: underline;
	}
</style>
<div id="content-right">
	<div id="add-product">
		<div id="sidebar-list" class="black">
			<div id="img-product" class="left white">
				 <?php echo $title?>
			</div>
			<div id="img-back" class="right">
				<a href="javascript:;" onclick="history.go(-1)" class="white">Quay lại trang trước </a>
			</div>
			<div class="clear"></div>
		</div>
		<div id="src-product" style="height:auto;">
			<form action="<?php echo base_url()?>back_end/admin_categories/search" method="post">
				<input type="hidden" name="domain" id="domain" value="<?php echo base_url();?>" />
				<table>
					<tr>
						<td>
							<select name="select_id" style="width: 150px; border: 1px solid #CCC; padding: 1px; height: 24px;">
								<option value="">-- Tìm kiếm theo --</option>
								<option value="1" <?php if(!empty($_SESSION['select_id'])){if($_SESSION['select_id'] == 1) echo 'selected="selected"';}?>>ID danh mục</option>
								<option value="2" <?php if(!empty($_SESSION['select_id'])){if($_SESSION['select_id'] == 2) echo 'selected="selected"';}?>>Tên danh mục</option>								
							</select>
						</td>
						<td><input type="text" name="name" placeholder="Nhập dữ liệu tương ứng" style="width: 200px; border: 1px solid #CCC; height: 24px;" <?php if(!empty($_SESSION['name'])){if($_SESSION['name'] != '0'){?> value='<?php echo $_SESSION['name'];?>' <?php }}?> /></td>
						<td><input type="submit" class="submit-src" name="cmd" value=' ' /></td>
					</tr>
				</table>				
			</form>	
		</div>
		<?php if (isset($_SESSION["permiss_error"]) && !empty($_SESSION["permiss_error"])){?>
			<div class="form-add" align="center" style="padding-bottom:15px;">
				<?php echo '<font style="color:red; text-align:center; font-size:15px;">'.$_SESSION['permiss_error'].'</font>'?>
			</div>
        <?php }$_SESSION["permiss_error"] = NULL;?>
		<form name="myform" id="myform" action="<?php echo base_url() ?>admins/admin_categories/delete" method="POST" onSubmit="return checkInput(this,'Bạn hãy chọn ít nhất một menu','Bạn có chắc muốn xóa không?');">
			<input type="hidden" id="chon" name="chon">
			<input type="hidden" id="domain" name="domain" value="<?php echo base_url()?>">
			<div id="select-product">
				<ul class="left">
					<li><a href="<?php echo base_url()?>admins/admin_categories/add">Thêm mới</a></li>
					<li> | </li>
					<li><a href="#"><span id="chk">0</span> đã chọn</a></li>
					<li> | </li>
					<li><input style="background-color: none; border: none; text-decoration: underline; color: #EF3503; font-family: Arial; cursor: pointer;" type="submit" name="cmd" value="Xóa"></li>
				</ul>
				<div class='clear'></div>
			</div>
			<div id="list-product">
				<table id="myTable" class="tablePr tablesorter" width="100%" border="0" cellspacing="0" cellpadding="0">
					<thead>
						<tr class="headerTbl">
							<td width="3%">STT</td>
							<td width="3%"><input id="checkall" type="checkbox" name="chkall" value="yes" onClick="docheck(this.form,0);" /></td>
							<th width="20%">Category Name</th>
							<th width="20%">Category</th>
							<th width="10%">Order</th>
							<th width="10%">Date</th>
							<td width="7%">Action</td>
						</tr>
					</thead>
					<?php if (!empty($menu_admin)){?>
						<tbody>
							<?php
								$i = 1; 
								foreach ($menu_admin as $menu) {
									if ($i % 2 == 0)
									{
										$bgcolor	= 'str1';
									}
									else
									{
										$bgcolor	= 'str2';
									}
							?>
							<tr class="<?php echo $bgcolor?>">
								<td><?php echo $i;?></td>
								<td><input type="checkbox" name="Xoa" value="<?php echo $menu['id']?>" onClick="docheckone(this.form);"/></td>
								<td style="text-align: left;">
									<a href="<?php echo base_url()?>admins/admin_categories/edit/<?php echo $menu['id']?>"><?php echo $menu['name'];?></a>
								</td>
								<td style="text-align: left;">
									<?php
										$cat_0	= $this->db->get_where('categories', array('status'=>1))->result_array();
										foreach ($cat_0 as $c0)
										{
											if ($c0['id'] == $menu['cat_id'])
											{
												echo '<a href="'.base_url().'admins/admin_categories/search_category/'.$c0['id'].'">'.$c0['name'].'</a>';
												
												foreach ($cat_0 as $c)
												{
													if ($c['cat_id'] == $c0['id'] && $c['id'] == $menu['cat_id'])
													{
														echo '<a href="'.base_url().'admins/admin_categories/search_category/'.$c['id'].'">'.$c['name'].'</a>';
														
														foreach ($cat_0 as $c2)
														{
															if ($c2['cat_id'] == $c['id'] && $c2['id'] == $menu['cat_id'])
															{
																echo '<a href="'.base_url().'admins/admin_categories/search_category/'.$c2['id'].'">'.$c2['name'].'</a>';
														
																foreach ($cat_0 as $c3)
																{
																	if ($c3['cat_id'] == $c2['id'] && $c3['id'] == $menu['cat_id'])
																	{
																		echo '<a href="'.base_url().'admins/admin_categories/search_category/'.$c3['id'].'">'.$c3['name'].'</a>';
																	}
																}
															}
														}
													}
												}												
											}
										}
									?>
								</td>
								<td>
									<?php if (!empty($menu['order'])){?>
									<select name="order" onchange="edit_order(<?php echo $menu['id'];?>, this)" style="width:70px; border: 1px solid #D1D0D0; padding: 1px;">
										<?php for ($j = 0; $j <=100; $j++){?>
											<option value="<?php echo $j?>" <?php if ($menu['order'] == $j) echo 'selected=selected'?>><?php echo $j?></option>
										<?php }?>
									</select>							
									<?php }?>		
								</td>
								<td><?php if (!empty($menu['createdate'])) echo date('d/m/Y', $menu['createdate'])?></td>
								<td>
									<a href="<?php echo base_url()?>admins/admin_categories/edit/<?php echo $menu['id']?>"><img width="16" height="16" src="<?php echo base_url()?>images/back_end/icon/edit-icon.png" title="Sửa tin tức <?php echo $menu['name'];?>" /></a>&nbsp;
									<a onclick="return confirm('Bạn có chắc chắn xóa <?php echo $menu['name'];?> ?');" href="<?php echo base_url()?>admins/admin_categories/delete/<?php echo $menu['id']?>"><img width="16" height="16" src="<?php echo base_url()?>images/back_end/icon/icon_del.gif" title="Xóa menu admin <?php echo $menu['name'];?>" /></a>&nbsp;
									<a href="<?php echo base_url()?>admins/admin_categories/active/<?php echo $menu['id']?>/<?php echo $menu['status']?>">
										<?php if ($menu['status'] == 1){?>
											<img src="<?php echo base_url()?>images/back_end/icon/Check-icon.png" alt="checked" title="Ẩn" />
										<?php } else {?>
											<img width="16" height="16" src="<?php echo base_url()?>images/back_end/icon/un-check.png" alt="check" title="Hiển thị" />
										<?php }?>
									</a>
								</td>
							</tr>
							<?php $i++;}?>
						</tbody>
					<?php }else{?>
						<tr><td colspan="7" style="padding: 15px;">Không có dữ liệu</td></tr>
					<?php }?>
				</table>
			</div>
		</form>
		<div id="pagingPr"><?php echo $paging?></div> 
	</div>
</div><!-- end  content-right -->	